﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;

namespace GloberoSport.Datos
{
    public class Track
    {
        public static DataTable buscar(int iTrackId)
        {
            dbManager db = new dbManager();

            //PARAMETROS 
            object[] parametros = new object[4];
            parametros[0] = "@id";
            parametros[1] = iTrackId;
            DataTable dt = db.EjecutarSP_DS("TRACK_OBTENER", parametros).Tables[0];
            return dt;
        }
        public static DataTable buscar(string sUsuario)
        {
            dbManager db = new dbManager();
            db.Conectar();

            //PARAMETROS 
            object[] parametros = new object[2];
            parametros[0] = "@pUsuario";
            parametros[1] = sUsuario;
            DataTable dt = db.EjecutarSP_DS("TRACK_OBTENER", parametros).Tables[0];
            db.Desconectar();
            return dt;
        }
        public static DataTable buscarUltima(string sUsuario)
        {
            dbManager db = new dbManager();
            db.Conectar();

            //PARAMETROS 
            object[] parametros = new object[2];
            parametros[0] = "@pUsuario";
            parametros[1] = sUsuario;
            DataTable dt = db.EjecutarSP_DS("TRACK_OBTENER_ULT", parametros).Tables[0];
            db.Desconectar();
            return dt;
        }

        public static int insertar
            (decimal dist, decimal aMax, decimal aTot, decimal vMed, decimal vMax, DateTime fIni, int tTot, string sTit, string sAutor)
        {
            int iRet = -1;
            object[] parametros = new object[18];
            parametros[0] = "@dist";
            parametros[1] = dist;
            parametros[2] = "@aMax";
            parametros[3] = aMax;
            parametros[4] = "@aTot";
            parametros[5] = aTot;
            parametros[6] = "@vMed";
            parametros[7] = vMed;
            parametros[8] = "@vMax";
            parametros[9] = vMax;
            parametros[10] = "@fIni";
            parametros[11] = fIni;
            parametros[12] = "@tTot";
            parametros[13] = tTot;
            parametros[12] = "@tTot";
            parametros[13] = tTot;
            parametros[14] = "@titulo";
            parametros[15] = sTit;
            parametros[16] = "@autor";
            parametros[17] = sAutor;

            dbManager db = new dbManager();
            db.Conectar();

            object salida = db.EjecutarSP("TRACK_INSERT", parametros);
            db.Desconectar();
            try
            {
                iRet = int.Parse(salida.ToString());
            }
            catch (Exception ex)
            {
                iRet = -10;
            }
            return iRet;
        }

        public static int modificar(int id, decimal dist, decimal aMax, decimal aTot, decimal vMed, decimal vMax, DateTime fIni, int tTot)
        {
            int iRet = -1;
            object[] parametros = new object[20];
            parametros[0] = "@id";
            parametros[1] = id;
            parametros[2] = "@dist";
            parametros[3] = dist;
            parametros[4] = "@aMax";
            parametros[5] = aMax;
            parametros[6] = "@aTot";
            parametros[7] = aTot;
            parametros[8] = "@vMed";
            parametros[9] = vMed;
            parametros[10] = "@vMax";
            parametros[11] = vMax;
            parametros[12] = "@fIni";
            parametros[13] = fIni;
            parametros[14] = "@tTot";
            parametros[15] = tTot;
            parametros[16] = "@titulo";
            parametros[17] = ".";
            parametros[18] = "@descripcion";
            parametros[19] = ".";

            dbManager db = new dbManager();
            object salida = db.EjecutarSP("TRACK_UPDATE", parametros);
            try
            {
                iRet = int.Parse(salida.ToString());
            }
            catch (Exception ex)
            {
                iRet = -10;
            }
            return iRet;
        }
    }
}

